package com.enqualcomm.kids.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.enqualcomm.kids.R;
import com.enqualcomm.kids.mvp.fillwatchinfo.SelectPetTypeRecycleViewAdapter;
import com.enqualcomm.kids.network.socket.response.QueryUserTerminalInfoResult;
import com.enqualcomm.kids.view.CircleImageView;
import com.enqualcomm.kids.view.ImageUtils;

import java.util.ArrayList;
import java.util.List;

import common.utils.DensityUtil;
import common.zxing.ZxingUtil;

/**
 * Created by sunzhigang on 2016/6/16.
 */
public class SelectPetTypeDialog extends Dialog {

    private RecyclerView recyclerView;

    private SelectPetTypeCallBack selectPetTypeCallBack;

    private Context mContext;
    private int type;


    public SelectPetTypeDialog(Context context, SelectPetTypeCallBack callBack) {
        super(context);
        this.selectPetTypeCallBack = callBack;
        this.mContext = context;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(R.layout.pet_type_select_dialog);

        setDialogAttributes();
        initDialogView();
    }

    public void setDialogAttributes() {
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
//        setCanceledOnTouchOutside(true);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        DisplayMetrics dm = new DisplayMetrics();
        dialogWindow.getWindowManager().getDefaultDisplay().getMetrics(dm);

        lp.width = dm.widthPixels - DensityUtil.dip2px(getContext(), 30); // 宽度
        // lp.alpha = 0.9f; // 透明度

        dialogWindow.setAttributes(lp);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    public void initDialogView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        SelectPetTypeRecycleViewAdapter adapter = new SelectPetTypeRecycleViewAdapter(mContext);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,
        StaggeredGridLayoutManager.VERTICAL));
        adapter.setImageClickListener(new SelectPetTypeRecycleViewAdapter.OnImageViewClickListenr() {
            @Override
            public void clickEvent(int i) {
                selectPetTypeCallBack.selected(i);
                dismiss();
            }
        });
    }
}
